package com.tudouji.project.d3.service.impl;

import java.util.List;
import com.tudouji.common.utils.DateUtils;
import com.tudouji.common.utils.SecurityUtils;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.project.d3.domain.D3ToSellform;
import com.tudouji.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tudouji.project.d3.mapper.D3ProToSpMapper;
import com.tudouji.project.d3.domain.D3ProToSp;
import com.tudouji.project.d3.service.ID3ProToSpService;

/**
 * 商品对应关系Service业务层处理
 * 
 * @author tudouji
 * @date 2023-04-10
 */
@Service
public class D3ProToSpServiceImpl implements ID3ProToSpService 
{
    @Autowired
    private D3ProToSpMapper d3ProToSpMapper;

    /**
     * 查询商品对应关系
     * 
     * @param id 商品对应关系ID
     * @return 商品对应关系
     */
    @Override
    public D3ProToSp selectD3ProToSpById(Long id)
    {
        return d3ProToSpMapper.selectD3ProToSpById(id);
    }

    /**
     * 查询商品对应关系列表
     * 
     * @param d3ProToSp 商品对应关系
     * @return 商品对应关系
     */
    @Override
    public List<D3ProToSp> selectD3ProToSpList(D3ProToSp d3ProToSp)
    {
        return d3ProToSpMapper.selectD3ProToSpList(d3ProToSp);
    }

    /**
     * 新增商品对应关系
     * 
     * @param d3ProToSp 商品对应关系
     * @return 结果
     */
    @Override
    public int insertD3ProToSp(D3ProToSp d3ProToSp)
    {
        Long user= SecurityUtils.getLoginUser().getUser().getUserId();
        System.out.println("-----------------"+user+"---------------------");
        d3ProToSp.setCreateTime(DateUtils.getNowDate());
        d3ProToSp.setCreateby(user);
        return d3ProToSpMapper.insertD3ProToSp(d3ProToSp);
    }

    /**
     * 修改商品对应关系
     * 
     * @param d3ProToSp 商品对应关系
     * @return 结果
     */
    @Override
    public int updateD3ProToSp(D3ProToSp d3ProToSp)
    {
        d3ProToSp.setUpdateTime(DateUtils.getNowDate());
        return d3ProToSpMapper.updateD3ProToSp(d3ProToSp);
    }

    /**
     * 批量删除商品对应关系
     * 
     * @param ids 需要删除的商品对应关系ID
     * @return 结果
     */
    @Override
    public int deleteD3ProToSpByIds(Long[] ids)
    {
        return d3ProToSpMapper.deleteD3ProToSpByIds(ids);
    }

    /**
     * 删除商品对应关系信息
     * 
     * @param id 商品对应关系ID
     * @return 结果
     */
    @Override
    public int deleteD3ProToSpById(Long id)
    {
        return d3ProToSpMapper.deleteD3ProToSpById(id);
    }

    @Override
    public AjaxResult insertD3ProToSpAll(List<D3ProToSp> d3ProToSps) {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();

        for (int i = 0; i < d3ProToSps.size(); i++) {
            D3ProToSp d3ToSellform = d3ProToSps.get(i);
            if (d3ToSellform.getId() == null){
                d3ToSellform.setCreateTime(DateUtils.getNowDate());
                d3ToSellform.setCreateby(sysUser.getUserId());
                d3ProToSpMapper.insertD3ProToSp(d3ToSellform);
            }else{
                d3ToSellform.setUpdateTime(DateUtils.getNowDate());
                d3ToSellform.setUpdateBy(sysUser.getUserId()+"");
                d3ProToSpMapper.updateD3ProToSp(d3ToSellform);
            }
        }
        return AjaxResult.success();
    }
}
